package pe.gob.mpfn.controller.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.roo.addon.jsf.converter.RooJsfConverter;
import pe.gob.mpfn.model.DetalleDiligencia;
import pe.gob.mpfn.service.DetalleDiligenciaService;

@FacesConverter("pe.gob.mpfn.controller.converter.DetalleDiligenciaConverter")
@Configurable
@RooJsfConverter(entity = DetalleDiligencia.class)
public class DetalleDiligenciaConverter implements Converter  {

	@Autowired
    DetalleDiligenciaService detalleDiligenciaService;

	public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (value == null || value.length() == 0) {
            return null;
        }
        Integer id = Integer.parseInt(value);
        return detalleDiligenciaService.findDetalleDiligencia(id);
    }

	public String getAsString(FacesContext context, UIComponent component, Object value) {
        return value instanceof DetalleDiligencia ? ((DetalleDiligencia) value).getIntDetalleDiligenciaId().toString() : "";
    }
}
